<?
layout("/inc/win_layout.html",{title:sysTitle}){
?>
	<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
	<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
    <script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
	<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<div id="page-wrapper" style="margin-left: 0px; ">

	<!--BEGIN CONTENT-->
	<div class="page-content"
		style="min-height: auto;padding-bottom: 20px; height: 590px; overflow: auto;">

		<div class="row mbl">
			<input id="chartId" type="hidden" class="form-control"  />
			<input id="payment" type="hidden" class="form-control" value="0" />
			<div class="panel">
				<div class="panel-body pan">

					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 400px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">中文名称
								<span class='require' >*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="analysisCnname" type="text" onchange="chinese_spell(this.value)" class="form-control" value="" />
								</div>
							</div>
						</div>
						<div id = "passwordParent" class="col-lg-6"
							style="width: 400px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">英文名称
								<span class='require' id="yonghu">*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="analysisEnname" type="text" class="form-control"
										value="" />
								</div>
							</div>
						</div>
					</div>
					
					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style="width: 400px; float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">图标（logo）
								<span class='require'>*</span></label>
							<div class="col-md-9">
								<div>
									<input id="avatarImg" type="text" class="form-control"
										value="" />
									<!-- <div style="display:inline " id="single"></div>
									<input type="button" style="width: 70px;height: 30px;padding: 0;background-color: #4cae4c;border-color: #4cae4c;" class="btn btn-primary" onclick="upImages()" value="上传图片"  />
									<textarea id="uploadImage" name="uploadImage"></textarea>
									<input id="avatarImg" type="hidden" class="form-control" value="" /> -->
								</div>
							</div>
						</div>
						<div class="col-lg-6"
							style="width: 400px; float:left; margin-right:-20px;display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">排序
								<span class='require'>*</span> </label>
							<div class="col-md-9">
								<div class="input-icon">
									<input id="analysisSort" type="text" class="form-control" />
								</div>
							</div>
						</div>
					</div>

					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-6"
							style=" float:left; margin-right:-20px; display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">简介</label>
							<div class="col-md-9">
								<div class="input-icon">
									<textarea rows="5" cols="99" id = "analysisSynopsis"></textarea>
								</div>
							</div>
						</div>
					</div>
					<hr>

					<div class="row" style="margin-bottom: 10px;">
						<div class="col-lg-12"
							style="width:98%; float:left; margin-right:-20px;display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">数据分析-知识库
								<span class='require'>*</span> </label>
							<div class="col-md-12">
								<div class="input-group input-group-sm mbs">
									<input id="libraryCnChoose" type="text"  value="" class="form-control" disabled="true" /> 
									<span class="input-group-btn">
										<button onclick="analysisClass()" id="classButton" type="button" data-toggle="dropdown" class="btn btn-success dropdown-toggle">选择...</button>
									</span> 
									<input id="libraryEnChoose" type="hidden" value="0" class="form-control" />
								</div>
							</div>
						</div>
					</div>
					<div class="row" style="margin-bottom: 10px;">
						<div class="col-xs-12"
							style="width:98%; float:left; margin-right:-20px;display:inline;">
							<label for="inputUsername" class="col-xs-12 control-label">数据分析-筛选条件
								<span class='require'>*</span> </label>
							<div class="col-xs-10" style="width:100%; float:left; ">
								<div class="input-group input-group-sm mbs">
									<input id="parentclassZhname" type="text"  value="" class="form-control" disabled="true" /> 
									<span class="input-group-btn">
										<button onclick="analysisCondition()" type="button" data-toggle="dropdown"  class="btn btn-success dropdown-toggle">选择...</button>
									</span> 
									<input id="parentClassEnname" type="hidden" value="0" class="form-control" />
								</div>
							</div>
						</div>
					</div>
					<div>
						<label for="inputUsername" class="col-md-3 control-label">
					 		<div align="right">是否开启对比
								<span class='require' id="paixu">*</span></div>
	                   	 </label>
						<div class="col-md-9" style="width:30%;>
							<div class="input-icon">
								<select id="analysisStauts" class="form-control">
									<option value="0">是</option>
									<option value="1">否</option>
								</select>
							</div>
						</div>
					</div>
					<div class="row" style="margin-bottom: 30px;margin-top:15px;">
						<div class="col-lg-12"
							style="width:98%; float:left; margin-right:-20px;display:inline;">
							<label for="inputUsername" class="col-md-3 control-label">分析指标
								<span class='require'>*</span> </label>
								<button type="button" style="height: 26px; width: 26px; padding: 0;" class="btn btn-success dropdown-toggle" onclick="analysisAnalyze('0')">+</button>
							<div class="col-xs-12" style = " margin-top: 10px; " id="chartParent">
								<!-- <div class="col-xs-6">
								    <div class="panel">
								        <div class="panel-body pan">
								            <div class="profile">
								                <div class="user-info" style="border: solid #999 1px;">
								                    <div style="margin-bottom: -15px" class="row">
								                        <div class="col-xs-6">
								                            <p>指标名称: </p>
								                            <p>分析字段:
								                            	<span class="label label-green mrs">人物库</span>
								                                <span class="label label-green mrs">机构库</span>
								                                <span class="label label-green mrs">文献库</span>
								                            </p>
								                            <p>图表类型:</p>
								                            <p>
					                              				 是否开启对比分析:
								                            </p>
								                            <p>
								                               	 操作:
								                                <button class="btn btn-sm btn-info" onclick="">编辑</button>
								                                <button class="btn btn-sm btn-primary" onclick="">删除</button>
								                            </p>
								                        </div>
								                        <div class="col-xs-4 text-center">
								                            <figure><img src="images/ziyuanku.jpg" alt="" style="display: inline-block" class="img-responsive" />
								                            </figure>
								                        </div>
								                    </div>
								                </div>
								            </div>
								        </div>
								    </div>
								</div> -->
								
								
								
							</div>
						</div>
					</div>

				</div>
			</div>


		</div>


	</div>

	<!--END CONTENT-->
</div>


<?} ?>
<script>
	var index1 = window.parent.getlay();
	var _editor;
	var screen = "";
	var chartId = "";
	function getscreen() {
		return screen;
	}
	function getChartId() {
		return chartId;
	}
	var libraryEnChoose;
	function getlibraryEnChoose() {
		return libraryEnChoose;
	}
	function getId() {
		return index1;
	}
	function getGraphId() {
		return graphId;
	}
	$(function() {
		if (index1 != 0) {
			
			$.ajax({
				type : "post",
				url : "./analysisUpdate.do",
				data : {
					"id" : index1,
				},
				dataType : "json",
				async : false,
				success : function(data) {
					if(data[0].msg== "OK"){
						$("#analysisCnname").val(data[0].data.nameZh);
						$("#analysisEnname").val(data[0].data.nameEn);
						document.getElementById('analysisEnname').disabled = true;
						/* $("#single").html("<img src='"+data[0].data.imgSrc+"' width='30' height='30'/>"); */
						$("#avatarImg").val(data[0].data.imgSrc);
						$("#analysisSort").val(data[0].data.sort);
						$("#analysisSynopsis").val(data[0].data.description);
						$("#libraryCnChoose").val(data[0].data.classesZh);
						$("#libraryEnChoose").val(data[0].data.classesEn);
						$("#parentclassZhname").val(data[0].data.conditionFieldsZh);
						$("#parentClassEnname").val(data[0].data.conditionFieldsEn);
						$("#analysisStauts").val(data[0].data.compare);
						$("#chartParent").html(showChart(data[0].data.chart));
						document.getElementById('classButton').disabled = true;
						
					}else{
						alert("请求失败");
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
		
		/*展示下面指标*/
		function showChart(chartData){
			var content = "";
			var chartId = $("#chartId").val();
			for(var i=0;i< chartData.length;i++){
				chartId +=chartData[i].id+";";
				content+='<div class="col-xs-6">';
				content+='<div class="panel">';
				content+='<div class="panel-body pan">';
				content+='<div class="profile">';
				content+='<div class="user-info" style="border: solid #999 1px;">';
				content+='<div style="margin-bottom: -15px" class="row">';
				content+='<div class="col-xs-6">';
				content+='<p>指标名称:&nbsp;&nbsp;'+chartData[i].chartName+'</p>';
				content+='<p>分析字段:&nbsp;&nbsp;'+chartData[i].analyzeZhName+'</p>';
				content+='<p>图表类型:&nbsp;&nbsp;'+chartData[i].analyzeChart+'</p>';
				content+='<p>是否开启对比分析:&nbsp;&nbsp;'+chartData[i].analyzeStauts+'</p>';
				content+='<p>操作:';
				content+=' <button class="btn btn-sm btn-info" onclick="analysisAnalyze('+chartData[i].id+')">编辑</button>';
				content+='&nbsp;<button class="btn btn-sm btn-primary" onclick="delChart('+chartData[i].id+')">删除</button>';
				content+='</p>';
				content+='</div>';
				content+='<div class="col-xs-6 text-center">';
				content+='<figure><img src="images/analysis-'+chartData[i].chartType+'.jpg" alt="" style="display: inline-block" class="img-responsive" />';
				content+='</figure>';
				content+='</div>';
				content+='</div>';
				content+='</div>';
				content+='</div>';
				content+='</div>';
				content+='</div>';
				content+='</div>';
			}
			$("#chartId").val(chartId);
			return content;
		}
		
		 _editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#avatarImg").val(urlPath);
						$("#single").html("<img src='"+urlPath+"' width='30' height='30' />");
	  	 			}
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	
		   	 });
	   }); 
	});
 	//上传图片
	function upImages() {
		var myFiles = _editor.getDialog("insertimage");
	  		myFiles.open();
	   
	}
	function SaveAnalysis() {
		if ($.trim($("#analysisCnname").val()).length < 1) {
			alert('专题中文名称不能为空！');
			return null;
		}
		if ($.trim($("#analysisEnname").val()).length < 1 && index1 == 0) {
			alert('专题英文名称不能为空！');
			return null;
		}
		if ($.trim($("#avatarImg").val()).length < 1) {
			alert('图标（logo）不能为空！');
			return null;
		}

		if ($.trim($("#analysisSort").val()).length < 1) {
			alert('请输入排序！');
			return null;
		}
		if ($.trim($("#libraryEnChoose").val()).length < 2) {
			alert('请选择要分析的知识库！');
			return null;
		}
		if ($.trim($("#parentClassEnname").val()).length < 2) {
			alert('请选择要筛选的条件');
			return null;
		}
		if ($.trim($("#chartId").val()).length < 1) {
			alert('请填写要分析的指标');
			return null;
		}

		$.ajax({
			type : "post",
			url : "./analysisSaveList.do",
			data : {
				"id":index1,
				"analysisCnname" : $("#analysisCnname").val(),
				"analysisEnname" : $("#analysisEnname").val(),
				"avatarImg" : $("#avatarImg").val(),
				"analysisSort" : $("#analysisSort").val(),
				"analysisSynopsis" : $("#analysisSynopsis").val(),
				"libraryEnChoose" : $("#libraryEnChoose").val(),
				"parentClassEnname" : $("#parentClassEnname").val(),
				"analysisStauts" : $("#analysisStauts").val(),
				"chartId" : $("#chartId").val()
			},
			dataType : "json",
			async : false,
			success : function(data) {
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				if(data[0].msg=="OK"){
					parent.layer.msg('提交成功');
					parent.layer.close(index);
				}else{
					alert("请求失败");
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	/*选择知识库*/
	
	function analysisClass() {
		libraryEnChoose = $("#libraryEnChoose").val();
		if(index1 == 0){
			if($.trim($("#libraryEnChoose").val()).length >1){
			
				if (confirm("您重新选择将清空筛选条件和分析指标，是否确定重新筛选！！"))
				{
					$("#chartParent").html("");
					$("#chartId").val("");
					$("#parentClassEnname").val("");
					$("#parentclassZhname").val("");
					parent.layer.open({
					type : 2,
					area : [ '500px', '500px' ],
					fix : false, //不固定
					scrollbar : false,
					shadeClose : true,
					//move : false,
					title:"推荐知识库",
					skin : 'layui-layer-rim', //加上边框
					btn : [ '保存 ', '关闭' ],
					content : ["analysis-Classes-recommendClass-zTree.html?winName="+window.name, 'no'],
					yes : function(index,layer) {	
				   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
						   iframeWin.analysisChoose();
						},
						cancel : function(index) {
						}
					});
				}
			}else{
				parent.layer.open({
				type : 2,
				area : [ '500px', '500px' ],
				fix : false, //不固定
				scrollbar : false,
				shadeClose : true,
				//move : false,
				title:"推荐知识库",
				skin : 'layui-layer-rim', //加上边框
				btn : [ '保存 ', '关闭' ],
				content : ["analysis-Classes-recommendClass-zTree.html?winName="+window.name, 'no'],
				yes : function(index,layer) {	
			   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
					   iframeWin.analysisChoose();
					},
					cancel : function(index) {
					}
				});
			}
		}
		
	};
	
	/*筛选条件*/
	
	function analysisCondition() {
		libraryEnChoose = $("#libraryEnChoose").val();
		if($.trim($("#libraryEnChoose").val()).length < 2){
			alert("请选择您要分析的知识库");
			return null;
		}
		parent.layer.open({
			type : 2,
			area : [ '500px', '500px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"推荐知识库",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["analysis-condition-recommendClass-zTree.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.save();
			},
			cancel : function(index) {
			}
		});
	};
	
	/*汉字转化拼音*/
	
   function chinese_spell(spell){
	  /* if(objectPropertyid == 0){ */
	  	/* if(cop == 00){ */
	  	var reg = "[A-Z]+";     
        var r = spell.match(reg);
	        if(r == null){
				$.ajax({
					type : "post",
					url : "pinYin.do",
					data : {
						"pinYin" : spell,
					},
					async : false,
					dataType : "json",
					success : function(data) {
						/* if(data[0].length > 20){ */
							$("#analysisEnname").val(data);
						/* } */
					},
					error : function(data) {
						alert("请求失败");
					}
				});
			}else{
				alert("英文名不可存在大写，请手动输入英文名");
				$("#analysisEnname").val("");
			}
		/* } */
		/* } */
	}
	
	/*跳转分析指标*/
	function analysisAnalyze(lid) {
		graphId = lid;
		libraryEnChoose = $("#libraryEnChoose").val();
		chartId = $("#chartId").val();
		if($.trim($("#libraryEnChoose").val()).length < 2){
			alert("请选择您要分析的知识库");
			return null;
		}
		parent.layer.open({
			type : 2,
			area : [ '500px', '550px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			//move : false,
			title:"分析指标",
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content : ["analysis-analyze-index-add-update.html?winName="+window.name, 'no'],
			yes : function(index,layer) {	
	   			var iframeWin = parent.window[layer.find('iframe')[0]['name']];
			   iframeWin.saveChart();
			},
			cancel : function(index) {
			}
		});
	};
	
	/*删除对应指标*/
	
	function delChart(analysisId){
		var chartIdAll = $("#chartId").val();
		libraryEnChoose = $("#libraryEnChoose").val();
		if (confirm("是否确认删除！！"))
		{
			$.ajax({
				type : "post",
				url : "./analysisDelChart.do",
				data : {
					"id" : analysisId,
					"chartId":chartIdAll,
					"libraryEnChoose":libraryEnChoose
				},
				dataType : "json",
				success : function(data) {
					if(data[0].msg == 'OK'){
						$("#chartId").val(data[0].chartId);
						var content = "";
						if(data[0].data.length>0){
							for(var i=0;i< data[0].data.length;i++){
								content+='<div class="col-xs-6">';
								content+='<div class="panel">';
								content+='<div class="panel-body pan">';
								content+='<div class="profile">';
								content+='<div class="user-info" style="border: solid #999 1px;">';
								content+='<div style="margin-bottom: -15px" class="row">';
								content+='<div class="col-xs-6">';
								content+='<p>指标名称:&nbsp;&nbsp;'+data[0].data[i].chartName+'</p>';
								content+='<p>分析字段:&nbsp;&nbsp;'+data[0].data[i].analyzeZhName+'</p>';
								content+='<p>图表类型:&nbsp;&nbsp;'+data[0].data[i].analyzeChart+'</p>';
								content+='<p>是否开启对比分析:&nbsp;&nbsp;'+data[0].data[i].analyzeStauts+'</p>';
								content+='<p>操作:';
								content+=' <button class="btn btn-sm btn-info" onclick="analysisAnalyze('+data[0].data[i].id+')">编辑</button>';
								content+='&nbsp;<button class="btn btn-sm btn-primary" onclick="delChart('+data[0].data[i].id+')">删除</button>';
								content+='</p>';
								content+='</div>';
								content+='<div class="col-xs-6 text-center">';
								content+='<figure><img src="images/analysis-'+data[0].data[i].chartType+'.jpg" alt="" style="display: inline-block" class="img-responsive" />';
								content+='</figure>';
								content+='</div>';
								content+='</div>';
								content+='</div>';
								content+='</div>';
								content+='</div>';
								content+='</div>';
								content+='</div>';
							}
						}
						$("#chartParent").html(content);
					}else{
						alert("请求失败");
					}
				},
				error : function(data) {
					alert("请求失败");
				}
			});
		}
	}
</script>